<?php
namespace jy_merch;
defined('BY_JYA') or exit('error');
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_merch/model')->方法名();
*/
class plugins extends \plugin{
	public function merch($merchid=0){
		$merchid=$merchid?:$_SESSION['merchid'];
		$list = array(
					array('title'=>'业务类','list'=>array(
						array('name'=>'jy_xiaoemerch','title'=>'小鹅多商户版','actionurl'=>'jy_xiaoemerch/merch.index/','desc'=>'商户预约活动'),
						array('name'=>'jy_mfuwu','title'=>'多商户上门服务','actionurl'=>'jy_mfuwu/manage.index/','desc'=>'商户自己的上门服务'),
						array('name'=>'jy_yuyue','title'=>'预约活动','actionurl'=>'jy_yuyue/merch.index/','desc'=>'商户预约活动'),
						array('name'=>'jy_zhaopin','title'=>'商户招聘','actionurl'=>'jy_zhaopin/merch.index/','desc'=>'商户招聘人才'),
					)),
					array('title'=>'营销类','list'=>array(
						array('name'=>'jy_mfee','title'=>'商户独立二级分销','actionurl'=>'jy_mfee/merch.index/','desc'=>'商户独立二级分销'),
						array('name'=>'jy_mareafee','title'=>'商户独立区域代理','actionurl'=>'jy_mareafee/merch.index/','desc'=>'商户独立区域代理'),
						array('name'=>'jy_mjicai','title'=>'多商户积分建仓版','actionurl'=>'jy_mjicai/merch.index/','desc'=>'多商户积分建仓版'),
						array('name'=>'jy_mteamfee','title'=>'商户团长极差分红','actionurl'=>'jy_mteamfee/merch.index/','desc'=>'商户团长极差分红'),
						array('name'=>'jy_area_jifee','title'=>'区域经销积分版','actionurl'=>'jy_area_jifee/merch.index/','desc'=>'区域经销积分版'),
						array('name'=>'jy_merchjifee','title'=>'商户团长级差积分版','actionurl'=>'jy_merchjifee/merch.index/','desc'=>'商户团长级差积分版'),
						array('name'=>'jy_merchteamfee','title'=>'多商户团长分红','actionurl'=>'jy_merchteamfee/merch.index/','desc'=>'团长分红，极差分红'),
						array('name'=>'jy_merch2fee','title'=>'独立多商户出局分销','actionurl'=>'jy_merch2fee/merch.index/','desc'=>'商户出局分销（2TO1）'),
						array('name'=>'jy_mshop2fee','title'=>'商户团队老板晋级分销','actionurl'=>'jy_mshop2fee/merch.index/','desc'=>'老板晋级出局分销（2TO1）'),
						array('name'=>'jy_bigwheel','title'=>'商户大转盘','actionurl'=>'jy_bigwheel/merch.index/','desc'=>'商户大转盘抽奖'),
						array('name'=>'jy_bargain','title'=>'砍价活动','actionurl'=>'jy_bargain/merch.index/','desc'=>'商户商品看见'),
						array('name'=>'jy_pingdd_pin','title'=>'拼团活动','actionurl'=>'jy_pingdd_pin/merch.index/','desc'=>'商户商品百人拼团！'),
						array('name'=>'jy_peimilk','title'=>'订奶配送系统多商户版','actionurl'=>'jy_peimilk/merch.index/','desc'=>'订奶配送系统多商户版','icon'=>'',),
						array('name'=>'jy_jibifee','title'=>'商户积分金币分销版','actionurl'=>'jy_jibifee/merch.index/','desc'=>'商户积分金币分销版','icon'=>'',),
						array('name'=>'jy_creditshop','title'=>'多商户积分商城','actionurl'=>'jy_creditshop/merch.index/','desc'=>'多商户积分商城','icon'=>'',),
						array('name'=>'jy_merch3fee','title'=>'商户出局团队奖分销','actionurl'=>'jy_merch3fee/merch.index/','desc'=>'新概念变现法','icon'=>'',),
						array('name'=>'jy_teamfee','title'=>'社区团长极差分红','actionurl'=>'jy_teamfee/merch.index/','desc'=>'社区团长极差分红','icon'=>'',),
						array('name'=>'jy_xunichong','title'=>'虚拟充值','actionurl'=>'jy_xunichong/merch.card/','desc'=>'自定义卡密虚拟充值'),
						array('name'=>'jy_mlianfee','title'=>'多商户生态链','actionurl'=>'jy_mlianfee/merch.index/','desc'=>'多商户生态链'),
						array('name'=>'jy_mjifee','title'=>'多商户绩效分润','actionurl'=>'jy_mjifee/merch.index/','desc'=>'多商户绩效分润'),
						array('name'=>'jy_globonus','title'=>'全民股东','actionurl'=>'jy_globonus/merch.index/','desc'=>'全民股东'),
						array('name'=>'jy_wteamfee','title'=>'企微员工分销','desc'=>'企微员工分销'),
					)),
					array('title'=>'工具类','list'=>array(
						array('name'=>'jy_merchscrm','title'=>'小云scrm多商户版','desc'=>'多商户企业微信scrm'),
						array('name'=>'jy_worker_ewm','title'=>'企微爆客码活码','desc'=>'商户企微爆客码活码'),
						array('name'=>'jy_goodsfwmerch','title'=>'农产品防伪溯源商户版','desc'=>'农产品防伪溯源商户版'),
						array('name'=>'jy_mbaoming','title'=>'在线报名多商户','desc'=>'在线报名多商户版'),
						//array('name'=>'jy_kefu','title'=>'全网客服','actionurl'=>'jy_kefu/merch.index/','desc'=>'7种客服方式选择','icon'=>'',),
						array('name'=>'jy_tbassistant','title'=>'淘宝助手','desc'=>'批量导入商品'),
						array('name'=>'jy_weishopniu','title'=>'电商客千牛','desc'=>'专注电商客商品批量操作'),
						array('name'=>'jy_m023sm','title'=>'多商户CES重要产品追溯上报','desc'=>'多商户CES重要产品追溯上报'),
					)),
		);
		foreach($list as &$type){
			foreach($type['list'] as $k=>&$p){
				$isplugin=pdo_get('core_plugins',array('name'=>$p['name']),array('id','title','image','hide'));
				if($isplugin['id']){
					$p['image']=$isplugin['image'];
					$p['title']=$isplugin['title'];
					$install = $this->check($merchid,$p['name']);
					if($install){
						$p['is_show'] = 1;
					}else{
						$p['is_show'] = 0;
					}
					$p['is_install'] = 1;
				}else{
					$p['is_install'] = 0;
				}
			}
		}
		return  $list;
	}
	public function check($merchid=0,$name='',$isexi=0){
		$pluginset=pdo_getcolumn('jy_merch_user',array('id'=>$merchid,'uniacid'=>$_SESSION['uniacid']),'pluginset');
		$pluginset=$pluginset?json_decode($pluginset,true):array('isopen'=>0);
		$plugins=$pluginset['plugins'];
		if(!$plugins){
			$groupid=pdo_getcolumn('jy_merch_user',array('id'=>$merchid,'uniacid'=>$_SESSION['uniacid']),'groupid');
			if(!$groupid){
				return true;
			}
			$plugins=pdo_getcolumn('jy_merch_group',array('id'=>$groupid,'uniacid'=>$_SESSION['uniacid']),'plugins');	
		}
		if($plugins){
			$check=strexists($plugins,';'.$name.';');	
			if(!$check){
				if($isexi){
						exi('没有访问权限','error',$group['menus'][0]['action']);
				}else{
					return false;	
				}
			}
		}
		return true;
	}
}